Skip to content

Conversation

@gone
Copy link

@gone gone commented Sep 2, 2025

rendered_content and render both evaluate data. If data contains a generator it will be exhausted in the first render and won't make it into the cache

@auvipy auvipy requested review from auvipy and Copilot September 16, 2025 15:29
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a bug where generators in response data were being exhausted due to double evaluation during caching. The issue occurred because the cache decorator was using rendered_content which re-evaluates the response data instead of using the already-rendered content.

  • Changes response.rendered_content to response.content in the cache decorator to prevent double rendering
  • Adds a comprehensive test case that demonstrates the generator exhaustion bug and verifies the fix

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
rest_framework_extensions/cache/decorators.py Changes cache decorator to use pre-rendered content instead of re-rendering
tests_app/tests/unit/cache/decorators/tests.py Adds test case to verify generator exhaustion bug is fixed

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

headers = {k: (k, v) for k, v in response.items()}
response_triple = (
response.rendered_content,
response.content, # FIX: Use already-rendered content
Copy link

Copilot AI Sep 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment should be more descriptive about why this change is necessary. Consider: '# Use already-rendered content to avoid re-evaluating generators and other iterables'

Suggested change
response.content, # FIX: Use already-rendered content
response.content, # Use already-rendered content to avoid re-evaluating generators and other iterables

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant